<%--
  Created by IntelliJ IDEA.
  User: 赵若松
  Date: 2021/8/16
  Time: 14:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>制造物联中间件系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/resources/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">工艺监控</a>
            <a href="">工艺要求</a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                       <span class="layui-inline layui-show-xs-block">
                            <select name="condition" id="condition">
                                <option value="technology_requirement_id">工艺要求编号</option>
                                <option value="technology_name">工艺名称</option>
                            </select>
                        </span>
                        <span class="layui-inline layui-show-xs-block">
                            <input type="text" name="conditionName" id="conditionName" placeholder="请输入搜索内容"
                                   autocomplete="off"
                                   class="layui-input">
                        </span>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="search" lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" id="delAll"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn" onclick="xadmin.open('添加用户','${pageContext.request.contextPath}/crafts/technologyPlan-add',600,600)"><i class="layui-icon"></i>添加</button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form"  id="test" lay-filter="test"></table>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="check">
    <input type="checkbox" name=""  lay-skin="primary">
</script>
<script type="text/html" id="role">

    <div>
        <a onclick="xadmin.open('工艺需求','${pageContext.request.contextPath}/technologyPlan/editText/'+'{{d.technologyRequirementId}}',600,420)" style="color: cadetblue">工艺需求</a>
    </div>

</script>
<script type="text/html" id="name">
    {{#  if( d.technologyModel!=null){      }}
    <span id="technologyName" onclick="xadmin.open('工艺名称','${pageContext.request.contextPath}/crafts/technology-edit?technologyId='+'{{d.technologyId}}',500,700)" style="color: cadetblue">{{d.technologyModel.technologyName}}</span>
    {{#  } else { }}
    <div>未命名</div>
    {{#  } }}
</script>
<script type="text/html" id="requ">
    {{#  if( d.technologyModel!=null){      }}
    <span id="technologyRequirementId">{{d.technologyRequirementId}}</span>
    {{#  } else { }}
    <div>未命名</div>
    {{#  } }}
</script>
<script>
    layui.use(['laydate','form','table','jquery','layedit'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer
        var layedit = layui.layedit
        //建立编辑器
        //编辑器中的工具
        let tool = [
            'strong' //加粗
            , 'italic' //斜体
            , 'underline' //下划线
            , 'del' //删除线
            , '|' //分割线
            , 'left' //左对齐
            , 'center' //居中对齐
            , 'right' //右对齐
            , '|' //分割线
            // , 'link' //超链接
            // , 'unlink' //清除链接
            , 'face' //表情
            // , 'image' //插入图片
            // , 'help' //帮助
        ]

        let index = layedit.build('note', {tool: tool});

        $(function (){
            table.render({
                elem: '#test'
                ,
                url: '${pageContext.request.contextPath}/technologyPlan/pagePlan?&condition=technology_requirement_id' + '&conditionName=' //数据接口
                // 对我们请求过来的数据进行一次预处理
                ,
                parseData(res) {
                    console.log(res)
                    if (res.success) {
                        return {
                            "code": 0, //解析接口状态, 等于0代表成功
                            "msg": res.msg, //解析提示文本
                            "count": res.data.total, //解析数据长度
                            "data": res.data.list//解析数据列表
                        }
                    } else {
                        layer.msg(res.msg);
                        return {
                            "code": res.code, //解析接口状态, 等于0代表成功
                            "msg": res.msg, //解析提示文本
                            "count": res.data.total, //解析数据长度
                            "data": res.data.list//解析数据列表
                        }
                    }
                },
                request: {
                    //页码的参数名称，默认：page，指定了页码的key
                    pageName: 'pageNum'
                    // 指定了每页容量的key
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                ,
                page: true //开启分页
                ,
                cols: [[ //表头
                    {type:'checkbox'},
                    {title: '工艺要求编号',templet: "#requ"},
                    {title: '工艺名称',templet: "#name"},
                    {title: '工艺要求', templet: "#role"},
                    {field: 'addTime', title: '工艺要求起始时间'},
                    {field: 'reviseTime', title: '工艺要求结束时间'},
                    {title: '操作', toolbar: '#barDemo', width: 150},

                ]]
            });
        })

        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });
        //查询
        form.on('submit(sreach)',
            function search(data)
            {
                table.render({
                    elem: '#test'
                    ,
                    url: '${pageContext.request.contextPath}/technologyPlan/pagePlan?&condition='+data.field.condition+'&conditionName=' + data.field.conditionName//数据接口
                    // 对我们请求过来的数据进行一次预处理
                    ,
                    parseData(res) {
                        if (res.success) {
                            return {
                                "code": 0, //解析接口状态, 等于0代表成功
                                "msg": res.msg, //解析提示文本
                                "count": res.data.total, //解析数据长度
                                "data": res.data.list//解析数据列表
                            }
                        } else {
                            layer.msg(res.msg);
                            return {
                                "code": res.code, //解析接口状态, 等于0代表成功
                                "msg": res.msg, //解析提示文本
                                "count": res.data.total, //解析数据长度
                                "data": res.data.list//解析数据列表
                            }
                        }
                    },
                    request: {
                        //页码的参数名称，默认：page，指定了页码的key
                        pageName: 'pageNum'
                        // 指定了每页容量的key
                        , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                    }
                    ,
                    page: true //开启分页
                    ,
                    cols: [[ //表头
                        {type:'checkbox'},
                        {title: '工艺要求编号',templet: "#requ"},
                        {title: '工艺名称',templet: "#name"},
                        {title: '工艺要求', templet: "#role"},
                        {field: 'addTime', title: '工艺要求起始时间'},
                        {field: 'reviseTime', title: '工艺要求结束时间'},
                        {title: '操作', toolbar: '#barDemo', width: 150},

                    ]]
                });
                return false;
            }
        )
        ;
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            console.log(obj)
            console.log("11223")

            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/technologyPlan/delplan",
                        type: "get",
                        data: {technologyRequirementId:obj.data.technologyRequirementId},
                        success(res) {
                            console.log(res)
                            if (res.success) {
                                obj.del();
                                layer.alert(res.msg)
                                layer.close(index);
                            } else {
                                layer.alert("删除失败", {
                                    icon: 6
                                });
                            }
                        }
                    })
                });
            } else if (obj.event === 'edit') {

                xadmin.open('编辑用户','${pageContext.request.contextPath}/crafts/technologyPlan-edit?technologyRequirementId='+obj.data.technologyRequirementId,600,600)
            }
        });
        //批量删除

        table.on('checkbox(test)', function (obj) {
            var checkStatus = table.checkStatus('test');
            console.log(checkStatus)
        })

        $("#delAll").on("click", function () {
            let ids2 = []
            let list = table.checkStatus('test').data;
            for (let i = 0; i < list.length; i++) {
                ids2.push(list[i].technologyRequirementId)
            }
            let ids = ids2.join(",")
            console.log(ids)
            $.ajax({
                url:"${pageContext.request.contextPath}/technologyPlan/delplanAll",
                type: "get",
                data: {ids:ids},
                success(res) {
                    if (res.success) {
                        layer.alert("成功", {
                            icon: 1
                        });
                        location.reload()
                    } else {
                        layer.alert("失败", {
                            icon: 6
                        });
                    }
                }
            })
        })

    });

</script>
</html>
